/*
	Copyright (c) 2007, ANYwebcam.com Pty Ltd. All rights reserved.

	The software in this package is published under the terms of the BSD style 
	license, a copy of which has been included with this distribution in the 
	license.txt file.
*/
package com.anywebcam.di.samples.movieApp
{
	/**
	 * 
	 */
	public class CSVMovieSource implements MovieSource
	{
		private var _movies:Array;

		/**
		 * @param
		 */
		public function CSVMovieSource( csv:String )
		{
			_movies = parse( csv );
		}
		
		protected function parse( csv:String ):Array
		{
			var movies:Array = [];
			var data:Array = csv.split(',');		
			if( data.length % 2 == 1 ) throw Error( 'Bad CSV data' );
			for( var i:int=0, n:int=data.length; i < n; i += 2 )
			{
				movies.push( new Movie( data[ i ], data[ i + 1 ] ) );
			}			
			return movies;
		}
		
		/**
		 * @inheritDoc
		 */
		public function getAll():Array // of Movie
		{
			return _movies;		
		}
	}
}